<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>商品分类管理</title>
	<meta name="decorator" content="default"/>
	<%@include file="/WEB-INF/views/include/treetable.jsp" %>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#treeTable").treeTable({expandLevel : 5});
			
			// 定义一个新的复制对象
			var clip = new ZeroClipboard($("a[id='clip_button']"), {
			  moviePath: "${ctxStatic }/ZeroClipboard/ZeroClipboard.swf"
			} );
			
			// 复制内容到剪贴板成功后的操作
			clip.on( 'complete', function(client, args) {
			   alert("复制成功，请到剪贴板粘帖！");
			} );
		});
        
        function updateSort() {
        	if(${fn:length(list)==0}){
        		alert("暂无可保存的信息.");
        		return;
        	}
        	loading('正在提交，请稍等...');
	    	$("#listForm").attr("action", "${ctx}/ivm/product/classify/updateSort");
	    	$("#listForm").submit();
    	}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/ivm/product/classify/list">分类列表</a></li>
		<shiro:hasPermission name="ivm:product:classify:edit"><li><a href="${ctx}/ivm/product/classify/form">分类添加</a></li></shiro:hasPermission>
	</ul>
	<tags:message content="${message}"/>
	<form id="listForm" method="post">
		<table id="treeTable" class="table table-striped table-bordered table-condensed">
			<thead>
				<tr>
					<th>名称</th>
					<th>分类级别</th>
					<th>电商地址</th>
					<th>备注</th>
					<th style="text-align:center;">排序</th>
					<shiro:hasPermission name="ivm:product:classify:edit"><th>操作</th></shiro:hasPermission>
				</tr>
			</thead>
			<tbody>
			<c:forEach items="${list}" var="productClassify" varStatus="ps">
				<tr id="${productClassify.id}" pId="${productClassify.parent.id==null?0:productClassify.parent.id}">
					<td style="width: 200px;">
						<input type="hidden" id="sort" name="sort" value="${productClassify.sort}"/>
						<input type="hidden" id="id" name="id" value="${productClassify.id}"/>
						<input type="hidden" id="shopUrl${ps.index }" name="shopUrl" value="${productClassify.shopUrl}"/>
						<a href="${ctx}/ivm/product/classify/form?id=${productClassify.id}">${productClassify.name}</a>
					</td>
					<td>${productClassify.level=='1'?'一级':'二级' }</td>
					<td style="width: 400px; word-break: break-all; word-wrap:break-word;">${productClassify.shopUrl }</td>
					<td>${productClassify.remarks}</td>
					<td style="text-align:center; width: 105px;">
						<shiro:hasPermission name="ivm:product:classify:edit">
							<input type="hidden" name="ids" value="${productClassify.id}"/>
							<input name="sorts" type="text" value="${productClassify.sort}" style="width:50px;margin:0;padding:0;text-align:center;" class="required digits">
						</shiro:hasPermission>
						<shiro:lacksPermission name="ivm:product:classify:edit">
							${productClassify.sort}
						</shiro:lacksPermission>
					</td>
					<shiro:hasPermission name="ivm:product:classify:edit"><td>
	    				<a href="${ctx}/ivm/product/classify/form?id=${productClassify.id}">修改</a>
						<a href="${ctx}/ivm/product/classify/delete?id=${productClassify.id}" onclick="return confirmx('确认要删除该商品分类吗？', this.href)">删除</a>
						<c:if test="${productClassify.level=='1'}">
						<a href="${ctx}/ivm/product/classify/form?level=2&parent.id=${productClassify.id}">添加二级分类</a> 
						<a href="javascript:" id="clip_button" data-clipboard-target="shopUrl${ps.index }">复制链接</a>
						</c:if>
					</td></shiro:hasPermission>
				</tr>
			</c:forEach>
			</tbody>
		</table>
		<shiro:hasPermission name="ivm:product:classify:edit">
		<div class="form-actions pagination-left">
		<input id="btnSubmit" class="btn btn-primary" type="button" value="保存排序" onclick="updateSort();"/>
		</div>
		</shiro:hasPermission>
	</form>
</body>
</html>
